import 'package:shelf_cors_headers/shelf_cors_headers.dart';
import 'package:shelf_plus/shelf_plus.dart';

void main() => shelfRun(init,defaultBindPort: 9601,defaultBindAddress: '0.0.0.0');

Handler init() {
  var app = Router().plus;
  app.use(corsHeaders()); // use CORS middleware

  app.get('/', () => {'data': 'This API is CORS enabled.'});
  app.get('/test', () => {'data': 'This API is CORS enabled.'});
  app.get(
    '/ws',
    () => WebSocketSession(
      onOpen: (ws) {},
      onClose: (ws) {},
      onMessage: (ws, dynamic data) {
        print(data);
        ws.send(data);
      },
    ),
  );
  return app;
}
